home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xless / xless141.z / xless141 / xless-1.4.1 / main.c < prev    next >
C/C++ Source or Header  |  1993-05-05  |  5KB  |  160 lines

  1. /*
  2.  * xless - X Window System file browser.
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author: Carlo Lisa
  24.  *       MIT Project Athena
  25.  *       carlo@athena.mit.edu
  26.  *
  27.  * Date: October 11, 1989
  28.  *
  29.  * $Header: /usr/sww/share/src/X11R5/local/clients/xless-1.4/RCS/main.c,v 1.23 1993/04/30 21:40:35 dglo Exp dglo $
  30.  */
  31.  
  32. #include "xless.h"
  33. #include "XLessTop.icon"
  34.  
  35. XtAppContext context;
  36. Widget toplevel;
  37. Display *disp;
  38.  
  39. XLessResources resources;
  40.  
  41. #define Offset(field) (XtOffset(XLessResources *, field))
  42.  
  43. static XtResource priv_resources[] = {
  44.   {"helpFile", XtCFile, XtRString, sizeof(char *),
  45.      Offset(help_file), XtRString, HELPFILE},
  46.   {"standardCur", XtCCursor, XtRCursor, sizeof(Cursor),
  47.      Offset(cursors.top), XtRString, STANDARDCUR},
  48.   {"dialogCur", XtCCursor, XtRCursor, sizeof(Cursor),
  49.      Offset(cursors.dialog), XtRString, STANDARDCUR},
  50.   {"standardFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  51.      Offset(fonts.standard), XtRString, STANDARDFONT},
  52.   {"textFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  53.      Offset(fonts.text), XtRString, TEXTFONT},
  54.   {"labelFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  55.      Offset(fonts.label), XtRString, LABELFONT},
  56.   {"buttonFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  57.      Offset(fonts.button), XtRString, BUTTONFONT},
  58.   {"editorDoesWindows", "EditorDoesWindows", XtRBoolean, sizeof(Boolean),
  59.      Offset(editorDoesWindows), XtRString, "False"},
  60.   {"printCommand", "PrintCommand", XtRString, sizeof(char *),
  61.      Offset(printCmd), XtRString, PRINTCMD},
  62.   {"printCmd", "PrintCommand", XtRString, sizeof(char *),
  63.      Offset(printCmd), XtRString, PRINTCMD},
  64.   {"maxWindows", "MaxWindows", XtRInt, sizeof(int),
  65.      Offset(maxWindows), XtRString, "0"},
  66.   {"quitButton", "QuitButton", XtRBoolean, sizeof(Boolean),
  67.      Offset(quitButton), XtRString, "False"},
  68.   {"textGeometry", "Geometry", XtRString, sizeof(char *),
  69.      Offset(textGeometry), XtRString, "80x25"},
  70.   {"sizeToFit", "SizeToFit", XtRBoolean, sizeof(Boolean),
  71.      Offset(sizeToFit), XtRString, "True"},
  72.   {"namePrefix", "NamePrefix", XtRString, sizeof(char *),
  73.      Offset(namePrefix), XtRString, "xless:"},
  74.   {"removePath", "RemovePath", XtRBoolean, sizeof(Boolean),
  75.      Offset(removePath), XtRString, "True"},
  76.   {"helpMessage", "HelpMessage", XtRBoolean, sizeof(Boolean),
  77.      Offset(helpMessage), XtRString, "False"},
  78. };
  79.  
  80. static XrmOptionDescRec options[] = {
  81.   {"-help",    "*helpMessage", XrmoptionNoArg, "True"},
  82. };
  83.  
  84. void
  85. cleanup()
  86. {
  87.   XtDestroyWidget(toplevel);
  88.   XtDestroyApplicationContext(context);
  89. }
  90.  
  91. void
  92. main(argc, argv)
  93. unsigned int argc;
  94. char *argv[];
  95. {
  96.   Arg    arg[10];
  97.   Cardinal n;
  98.   int i;
  99. #ifdef _DEBUG_MALLOC_INC
  100.   {
  101.     union dbmalloptarg    moa;
  102.  
  103.     moa.i = 0;
  104.     dbmallopt(MALLOC_CKCHAIN, &moa);
  105.   }
  106. #endif
  107.  
  108.   toplevel = XtAppInitialize(&context, XLESS_CLASS, NULL, (Cardinal )0,
  109.                  &argc, argv, NULL, NULL, 0);
  110.  
  111.   XtGetApplicationResources(toplevel, (XtPointer )&resources, priv_resources,
  112.                 XtNumber(priv_resources), NULL, (Cardinal) 0);
  113.  
  114.   XtAppAddActions(context, actions, numactions);
  115.  
  116.   disp = XtDisplay(toplevel);
  117.  
  118.   n = 0;
  119.   XtSetArg(arg[n], XtNiconPixmap,
  120.        XCreateBitmapFromData(disp, XRootWindow(disp, 0),
  121.                  XLessTop_bits, XLessTop_width,
  122.                  XLessTop_height)); n++;
  123.   XtSetValues(toplevel, arg, n);
  124.  
  125.   CheckFonts();
  126.  
  127.   for (i = 1; resources.helpMessage || i < argc; i++) {
  128.  
  129.     /* whine if there's still an argument */
  130.     if (resources.helpMessage || *argv[i] == '-') {
  131.       fprintf(stdout, "usage:\txless filename\n");
  132.       fprintf(stdout, "\t(xless also takes input from stdin)\n");
  133.       cleanup();
  134.       exit(0);
  135.     }
  136.  
  137.     CreateWindow(toplevel, argv[i]);
  138.   }
  139.  
  140.   /* if we haven't opened a window yet... */
  141.   if (windowcount == 0) {
  142.     /*
  143.      * Not really necessary to call this an error,
  144.      * but if the control terminal (for commands)
  145.      * and the input file (for data) are the same,
  146.      * we get weird results at best.
  147.      */
  148.     if (isatty(fileno(stdin))) {
  149.       fprintf(stderr, "xless: can't take input from terminal\n");
  150.       cleanup();
  151.       exit(1);
  152.     }
  153.  
  154.     /* bring up controlling window using stdin as input */
  155.     CreateWindow(toplevel, NULL);
  156.   }
  157.  
  158.   XtAppMainLoop(context);
  159. }
  160.